import React from 'react';
import {
	ActivityIndicator,
	AsyncStorage, Image,
	StatusBar,
	StyleSheet,
	View,
} from 'react-native';
import CookieManager from "react-native-cookies";
var Common = require('./common');

export default class AuthLoadingScreen extends React.Component {

	static navigationOptions = {
		headerTitle: '我的',
		tabBarLabel: '我的',
		tabBarIcon: ({focused}) => {
			if (focused) {
				return (
					<Image style={{height: 30, width: 30}}
					       source={require('./images/wode1.png')}/>
				);
			}
			return (
				<Image style={{height: 30, width: 30}}
				       source={require('./images/wode.png')}/>
			);
		},
	};

	componentDidMount() {
		this._bootstrapAsync();
	}

	// Fetch the token from storage then navigate to our appropriate place
	_bootstrapAsync = async () => {
		const userToken = await AsyncStorage.getItem('userToken');
		console.log(userToken);
		AsyncStorage.getItem('logindata').then((value)=>{
			if(value){
				this.props.navigation.navigate('Mine');
			}else{
				this.props.navigation.navigate('Login')
			}
		})

		// CookieManager.get(Common.url)
		// 	.then((res) => {
		// 		console.log('CookieManager.get =>', res); // => 'user_session=abcdefg; path=/;'
				// if(Object.keys(res).length == 0){
					// this.props.navigation.navigate('Login');
				// }
				// else{
				// 	this.props.navigation.navigate('Mine');
				// }
			// });
		// this.props.navigation.navigate('Mine')
		// This will switch to the App screen or Auth screen and this loading
		// screen will be unmounted and thrown away.

	};

	// Render any loading content that you like here
	render() {
		return (
			<View>
				<ActivityIndicator />
				<StatusBar barStyle="default" />
			</View>
		);
	}
}
